import static java.lang.Math.pow;

/**
 * Created with IntelliJ IDEA.
 * Description: ${DESCRIPTION}
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static int sumBit(int n) {
        int sum =0;
        while(n != 0) {
            sum += pow(n%10,2);//力扣当中没有这个pow这个方法.
            n /=10;
        }
        return sum;
    }


    public static boolean isHappy(int n) {
        int slow = n;
        int fast = sumBit(sumBit(n));
        if(n == 1)
            return true;
        while(slow != fast) {
            slow = sumBit(slow);
            fast = sumBit(sumBit(fast));
        }
        return slow == 1;
    }


    public static void main(String[] args) {
        System.out.println(isHappy(7));
    }
}